package duyd.hibernate.training.test;

import javax.persistence.EntityManager;

import org.junit.Test;

import duyd.hibernate.training.domain.Event;

public class HibernateCache extends HibernateJPA {

	@Test
	public void test() {
//		EntityManager entityManager = entityManagerFactory
//				.createEntityManager();
//		entityManager.getTransaction().begin();
//		entityManager.persist(new Event("Our very first event!", new Date()));
//		entityManager.persist(new Event("A follow up event", new Date()));
//		entityManager.getTransaction().commit();
//		entityManager.close();

		EntityManager entityManager = entityManagerFactory.createEntityManager();
		entityManager.getTransaction().begin();
		Event event = entityManager.find(Event.class, 2L);
		System.out.println(event.getTitle());
		entityManager.getTransaction().commit();
		entityManager.close();

		entityManager = entityManagerFactory.createEntityManager();
		entityManager.getTransaction().begin();
		event = entityManager.find(Event.class, 2L);
		System.out.println(event.getTitle());
		entityManager.getTransaction().commit();
		entityManager.close();
	}

}
